/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.merb.client.ui;

import co.com.merb.client.service.LoginService;
import co.com.merb.client.service.LoginServiceAsync;
import co.com.merb.client.ui.menu.InicioPane;
import co.com.merb.shared.i18n.MerbConstants;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.smartgwt.client.util.SC;

/**
 *
 * @author alexkbra
 */
public class ValidacionInicio {
    private final MerbConstants constants;
    private final LoginServiceAsync serviceLogin;

    public ValidacionInicio() {
        this.constants = GWT.create(MerbConstants.class);
        this.serviceLogin = GWT.create(LoginService.class);
    }
    
    public void verificarSesion() {
        serviceLogin.verificarSesion(new AsyncCallback<String>() {
            @Override
            public void onFailure(Throwable caught) {
                SC.say(constants.MensajeError(), caught.getMessage());
            }

            @Override
            public void onSuccess(String result) {
                if (result != null) {
                    InicioPane inicioPane = new InicioPane();
                    inicioPane.show();
                }else{
                    Login login = new Login();
                    login.show();
                }
            }
        });
    }
    
}
